package com.just.just_bankreputationsystem.Service.BankServiceImpl;

import com.just.just_bankreputationsystem.Mapper.BankMapper;
import com.just.just_bankreputationsystem.Model.Bank;
import com.just.just_bankreputationsystem.Model.Page;
import com.just.just_bankreputationsystem.Service.BankService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BankServiceImpl implements BankService {
    @Autowired
    private BankMapper bankMapper;


    @Override
    public List<Bank> selectAllbank() {
        return bankMapper.show();

    }

    @Override
    public int bankAdd(Bank bank) {
        return bankMapper.add(bank);

    }

    @Override
    public void delBankById(int id) {
        bankMapper.delBank(id);
    }

    @Override
    public Bank selectBankById(int id) {
        return bankMapper.selectBank(id);
    }

    @Override
    public int updateBank(Bank bank) {
        return bankMapper.update(bank);
    }

      @Override
    public Page getPage() {
        //获取数据库中的数据
        List<Bank> banks = selectAllbank();
        Page page = new Page();
        page.setPageSize(10); //设置每页展示的数据条数
        //计算出一共有几页
        page.setPageNum((int) Math.ceil((double)banks.size()/(double)page.getPageSize()));
        //将数据方药页面中
        page.setContent(banks);
        return page;
    }
}
